package com.oo.array_$.case_1;

/**
 * YangHui--使用多重循环打印 6 阶杨辉三角
 *
 * @author: Jovi
 * @createTime: 2017-05-11 14:41
 **/
public class YangHui {

    public static void main(String[] args) {
        int[][]a = new int[6][6];
        //为第一列和对角线元素赋值，均为1
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j <= i; j++) {
                if (i == 0 || i == j) {
                    a[i][j] = 1;
                }
            }
        }
        //为非第一列和对角线元素赋值
        for (int i = 1; i < a.length; i++) {
            for (int j = 1; j < i; j++) {
                a[i][j] = a[i - 1][j] + a[i - 1][j - 1];
            }
        }
        //输出杨辉三角
        for (int i = 0; i < a.length; i++) {
            for (int j = 0; j <= i; j++) {
                System.out.print(a[i][j]+"");
            }
            System.out.println();
        }
    }
}
